<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>Cesium地球初始化</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box {
            display: grid;
            grid-template-columns: 100px 1fr;
            margin-bottom: 10px;
            align-items: center;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for=""> 编辑</label> <input type="checkbox" id="editing" onchange="editing()">
        </div>
        <div class="box">
            <label for="">显示锥体</label> <input type="checkbox" checked onchange="showFrustum()">
        </div>
        <div class="box">
            <label for=""> 视频路径</label> <input type="text" id="vedioPath" onchange="vedioPath()"
                value="https://cdn2-unrealengine-1251447533.file.myqcloud.com/homepage-opener-5a55a50aaa4c.mp4">
        </div>
        <div class="box">
            <label for=""> 视域夹角</label> <input type="text" id="fov" value="90" onchange="fov()">
        </div>
        <div class="box">
            <label for=""> 显示优先级</label> <input type="text" id="zindex" value="1" onchange="zindex()">
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/
        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']
        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;
        // 监听视口状态
        objm.viewerCreatedEvent.don((viewer) => {
            viewer.flyIn(
                [
                    108.96708085773535,
                    34.21365588348781,
                    826.952187784194
                ], [
                303.9941519186465,
                -28.05758861619508,
                0.00007180136614638873
            ], 3
            )
        });
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer(document.getElementById("app"));

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 16,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });


        /** ---------------------------------------视频融合------------------------------------------**/
        /**
         * 视频融合
         * 在ue中视频融合可以投到瓦片和地形上
         * 在cesium中视频融合可以投到瓦片上
         * 
        */
        //添加瓦片用来投放视频
        const ES3DTileset = objm.createSceneObjectFromJson({
            "id": "c2c8311e-6e50-47a2-b764-1c82f2d0e256",
            "type": "ES3DTileset",
            "name": "大雁塔",
            "allowPicking": true,
            "url": "https://www.earthsdk.com/assets/tileset/osgb_dayanta/tileset.json"
        })

        // 创建一个视频融合对象
        const sceneObject = objm.createSceneObjectFromJson({
            "type": "ESVideoFusion",
            "position": [108.95940620973573, 34.21785533716187, 419.4659565408284],
            "rotation": [-91.61253930450191, 1.8246546474987793, 0],
            "far": 200,
            "videoStreamUrl": "https://cdn2-unrealengine-1251447533.file.myqcloud.com/homepage-opener-5a55a50aaa4c.mp4"
        })
        // 编辑对象
        function editing() {
            sceneObject.editing = !sceneObject.editing

        }
        /**
       * 监听对象的编辑状态，改变checkbox的状态
       * 用法 对象名.属性名+Changed.don((val)=>{})
       * don是disposableOn的简写形式，用来监听事件，相当于Vue中的watch用途，都是监听属性事件的变化
       */
        sceneObject.editingChanged.don((val) => {
            document.getElementById('editing').checked = val
        })

        // 视频播放地址
        function vedioPath() {
            sceneObject.videoStreamUrl = document.getElementById("vedioPath").value
        }

        /**
         * 视域夹角
         * 属性值范围为0-180，不为0或180。
         * */
        function fov() {
            sceneObject.fov = document.getElementById("fov").value
        }

        // 显示优先级
        function zindex() {
            sceneObject.zIndex = document.getElementById("zindex").value
        }

        // 是否显示锥体
        function showFrustum() {
            sceneObject.showFrustum = !sceneObject.showFrustum
        }

    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>